﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using WinFormsAppTest.Dao;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace WinFormsAppTest
{
    public partial class AdminAddForm : Form
    {
        //
        public String username = "null";//设置默认登录用户(手动添加)
        public int id = 0;//设置默认登录用户(手动添加)
        //
        public AdminAddForm()
        {
            InitializeComponent();
        }

        // -------有参 窗口（手动添加）--------
        public AdminAddForm(String name, int uid)
        {
            username = name;
            id = uid;
            InitializeComponent();
        }
        //-----------------------------------

        private void OKbutton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(UserNametextBox.Text))
            {
                MessageBox.Show("添加账号不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(PasswordtextBox.Text))
            {
                MessageBox.Show("添加密码不能为空！");
            }

            if (!string.IsNullOrWhiteSpace(UserNametextBox.Text)
                && !string.IsNullOrWhiteSpace(PasswordtextBox.Text))
            {
                //直接调用dao层进行添加
                AdminDao testdao = new AdminDao();
                testdao.CreateAdmin(UserNametextBox.Text, PasswordtextBox.Text);
                MessageBox.Show("添加成功！");
                AdminManageForm f2 = new AdminManageForm(username, id);
                this.Hide();
                f2.ShowDialog();
                this.Dispose();

            }
        }

        private void Exitbutton_Click(object sender, EventArgs e)
        {
            AdminManageForm f2 = new AdminManageForm(username, id);
            this.Hide();
            f2.ShowDialog();
            this.Dispose();
        }

        private void AdminAddForm_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                // 关闭进程
                Process.GetCurrentProcess().Kill();
            }
        }
    }
}
